home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_devices / rkrm_devices.lha / Parallel / Terminate_Parallel.c < prev   
C/C++ Source or Header  |  1992-09-03  |  5KB  |  130 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  ******************************************************************************
  27.  *
  28.  * Terminate_Parallel.c
  29.  *
  30.  * This is an example of using a termination array for writes from the parallel
  31.  * device. A termination array is set up for the characters Q, E, A and %.  The
  32.  * EOFMODE flag is set in io_ParFlags to indicate that we want to use a
  33.  * termination array by sending the PDCMD_SETPARAMS command to the device.
  34.  * Then, a CMD_WRITE command is sent to the device with io_Length set to -1.
  35.  *
  36.  * The write will terminate when one of the four characters in the
  37.  * termination array is sent or when the end of the write buffer has been reached.
  38.  *
  39.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  40.  *
  41.  * Run from CLI only
  42.  *
  43.  */
  44.  
  45. #include <exec/types.h>
  46. #include <exec/memory.h>
  47. #include <exec/io.h>
  48. #include <devices/parallel.h>
  49.  
  50. #include <clib/exec_protos.h>
  51. #include <clib/alib_protos.h>
  52.  
  53. #include <stdio.h>
  54. #include <string.h>
  55.  
  56. #ifdef LATTICE
  57. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  58. int chkabort(void) { return(0); }  /* really */
  59. #endif
  60.  
  61. void main(void)
  62. {
  63. struct MsgPort  *ParallelMP;          /* Define storage for one pointer */
  64. struct IOExtPar *ParallelIO;         /* Define storage for one pointer */
  65.  
  66. struct IOPArray Terminators =
  67. {
  68. 0x51454125,   /* Q E A % */
  69. 0x25252525    /* fill to end with lowest value, must be in descending order */
  70. };
  71.  
  72. UBYTE *WriteBuffer = "abcdefghijklmEopqrstuvwxyz";
  73. UWORD ctr;
  74.  
  75. if (ParallelMP=CreatePort(0,0))
  76.     {
  77.     if (ParallelIO=(struct IOExtPar *)
  78.                     CreateExtIO(ParallelMP,sizeof(struct IOExtPar)) )
  79.         {
  80.         if (OpenDevice(PARALLELNAME,0L,(struct IORequest *)ParallelIO,0) )
  81.             printf("%s did not open\n",PARALLELNAME);
  82.         else
  83.             {
  84.              /* Tell user what we are doing */
  85.              printf("\fWriting until Q, E, A or % encountered in output\n");
  86.  
  87.              /* Set EOF mode flag
  88.               * Set the termination array
  89.               * Send PDCMD_SETPARAMS to the parallel device
  90.               */
  91.              ParallelIO->io_ParFlags |= PARF_EOFMODE;
  92.              ParallelIO->io_PTermArray = Terminators;
  93.              ParallelIO->IOPar.io_Command  = PDCMD_SETPARAMS;
  94.              if (DoIO((struct IORequest *)ParallelIO))
  95.                  printf("Set Params failed ");   /* Inform user of error */
  96.              else
  97.                  {
  98.                  /* Send buffer */
  99.                  ParallelIO->IOPar.io_Length   = -1;
  100.                  ParallelIO->IOPar.io_Data     = WriteBuffer;
  101.                  ParallelIO->IOPar.io_Command  = CMD_WRITE;
  102.                  if (DoIO((struct IORequest *)ParallelIO))
  103.                      printf("Error: Write failed\n");
  104.                  else
  105.                      {
  106.                       printf("\nThe total buffer length was: %d.\n"
  107.                              "The actual number of characters sent: %d\n",
  108.                              strlen(WriteBuffer),ParallelIO->IOPar.io_Actual);
  109.  
  110.                       /* Display all characters sent */
  111.                       printf("\nThese characters were sent:\n\t\t\tASCII\tHEX\n");
  112.                       for (ctr=0;ctr<ParallelIO->IOPar.io_Actual;ctr++)
  113.                            printf("\t\t\t%c\t%x\n",*WriteBuffer,*WriteBuffer++);
  114.                       }
  115.                  }
  116.  
  117.             CloseDevice((struct IORequest *)ParallelIO);
  118.             }
  119.  
  120.         DeleteExtIO((struct IORequest *)ParallelIO);
  121.         }
  122.     else
  123.         printf("Error: Could not create IORequest\n");
  124.  
  125.     DeletePort(ParallelMP);
  126.     }
  127. else
  128.     printf("Error: Could not create message port\n");
  129. }
  130.